const fs = require("fs");
const _ = require("lodash");
// const path = require("path");
// const exec = require('child_process').exec;
const shell = require("shelljs");


let comApp = {
  setFis() {
    let data = fs.readFileSync("./fis-conf.js");
    let str = data.toString();
    let flagStr = `let versionRandow = '?v=' + (Date.now() + "").slice(0, 9);`;
    let flag1Str = `let versionRandow = '?vt=' + (Date.now() + "").slice(0, 9);`;
    let rdata = ""
    if (str.indexOf(flagStr) >= 0) {
      rdata = str.replace(flagStr, flag1Str);
    } else {
      rdata = str.replace(flag1Str, flagStr);
    }
    fs.writeFileSync("./fis-conf.js", rdata);
    console.log("fis文件配置完成");
  },
  path1: "../publish",
  pub() {
    let baseP="../biglotto1708"
    let pubPath = baseP+"/web/";
    this.pub1();

    shell.exec(`sudo rm -rf ${pubPath}*`);
    console.log("start cp...");
    shell.exec(`sudo mkdir ${pubPath}c`);
    shell.exec(`sudo cp -R ${this.path1}/c ${pubPath}`);
    shell.exec(`sudo mkdir ${pubPath}j`);
    shell.exec(`sudo cp -R ${this.path1}/j  ${pubPath}`);
    shell.exec(`sudo mkdir ${pubPath}i`);
    shell.exec(`sudo cp -R ${this.path1}/i ${pubPath}`);

    shell.exec(`find ${pubPath} -name .DS_Store | xargs rm -f`);
    console.log("开始压缩...");

    shell.exec(`rm -rf ${baseP}.zip`);
    shell.exec(` 7z a ${baseP}.zip ${baseP}`);


  },
  pub1() {
    shell.exec(`sudo rm -rf ${this.path1}*`);
    shell.exec(`sudo fis3 release prod1 -d ${this.path1}`);
  },
  run() {
    this.setFis();
    this.pub();
  }
}

comApp.run();